package com.artisan.provider.service.impl;

import com.artisan.provider.domain.ZgDiscountCode;
import com.artisan.provider.dto.ZgDiscountCodeDto;
import com.artisan.provider.mapper.ZgDiscountCodeMapper;
import com.artisan.provider.service.ZgDiscountCodeService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ZgDisCountCodeServiceImpl implements ZgDiscountCodeService {

    @Autowired
    ZgDiscountCodeMapper zgDiscountCodeMapper;

    @Override
    public List<ZgDiscountCode> findAll(ZgDiscountCodeDto zgDiscountCodeDto, int page, int limit) {
        if(page > 0 && limit > 0){
            PageHelper.startPage(page,limit);
        }
        return zgDiscountCodeMapper.findAll(zgDiscountCodeDto);
    }

    @Override
    public int zgDiscountCodeAdd(ZgDiscountCode zgDiscountCode) {
        int i = 0;
        try {
            return zgDiscountCodeMapper.insertSelective(zgDiscountCode);
        }catch (Exception e){
            return i;
        }

    }

    @Override
    public int zgDiscountCodeUpdate(ZgDiscountCode zgDiscountCode) {
        int i = 0;
        try {
            return zgDiscountCodeMapper.updateByPrimaryKeySelective(zgDiscountCode);
        }catch (Exception e){
            return i;
        }
    }

    @Override
    public int zgDiscountCodeDelete(int id) {
        return zgDiscountCodeMapper.deleteByPrimaryKey(id);
    }
}
